Lasso Soft Inc. > Home

[file->setattr]

Linkfile->setattr
AuthorKe Carlton
CategoryFile
Version9.x
LicensePublic Domain
Posted09 Jul 2013
Updated09 Jul 2013
More by this author...

Description

Sample Usage

local(f) = file('///tmp/myfile.txt')

#f->setattr('user.checksum'='xyz','user.example'='abc')

#f->getattr('user.checksum') // xyz


Source Code

Click the "Download" button below to retrieve a copy of this tag, including the complete documentation and sample usage shown on this page. Place the downloaded ".inc" file in your LassoStartup folder, restart Lasso, and you can begin using this tag immediately.

/*	---------------------------------------------------------------
//
//	Extended file attributes
//
//	Reference: http://en.wikipedia.org/wiki/Extended_file_attributes
*/

define file->setattr(name::string,value::string,silent::boolean=true) => {
	//	Linux / OSX only, adjust setfattr path accordingly
	//	Namespaces:  	user, trusted, security and system 
	//	Example usage:	file->setattr('user.checksum','xyz')

	local(
		p = sys_process('/usr/bin/setfattr',staticarray('-n',#name,'-v',#value,file_forceroot(.path)->replace('//','/')&))->wait &,
		e = #p->readerror,
		s = #p->readstring
	)

	handle => {#p->close}
	
	not #silent && #e ? fail(-1,#e->asstring)
        return  #s
}

define file->setattr(p::pair,...) => {
	//	Example usage:	file->setattr('user.checksum'='xyz','user.example'='abc')
	.setattr(#p->name,#p->value)
	with p in #rest do {
		#p->isa(::pair) ? .setattr(#p->name,#p->value)
	}
}

Comments

No comments

Please log in to comment

Subscribe to the LassoTalk mail list

LassoSoft Inc. > Home

 

 

©LassoSoft Inc 2015 | Web Development by Treefrog Inc | PrivacyLegal terms and Shipping | Contact LassoSoft